<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;

class UserWishOrder extends Model
{
    //定义一个表名
    protected $table = 'user_wish_order';
    //定义主键
    protected $primaryKey = 'id';
    protected $guarded = [];

	//生成订单号
	public static function make_no()
	{
		// 订单流水号前缀
		$prefix = "s".date('YmdHis');
		for ($i = 0; $i < 10; $i++) {
			// 随机生成 6 位的数字
			$no = $prefix.str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
			// 判断是否已经存在
			if (!empty(self::where('on_sn',$no)->first())) {
				$no = self::make_no();
			}
		}
		return $no;
	}
}
